<?
$zdir = 1;
include('functions.php');
$rootDirectory = ROOT_DIR.'docs/';

// ***** RENAME A FILE **********************************************
if ($_POST[cmd] == 'rename') {
	$nameOld = $_POST[oldname];
	$nameNew = $_POST[newname];
	echo '{"success":false,"error":"Cannot rename file '.$nameOld.' to '.$nameNew.'"}';
} 

// ***** DELETE A FILE **********************************************
elseif ($_POST[cmd] == 'delete') {
	$deletedFile = $_POST[file];
	
} 

// ***** UPLOAD A FILE **********************************************
elseif ($_POST[cmd] == 'upload') {
//elseif ($_GET[upload] == 1) {
	$uploadedFile = $_POST[path];
	$files = count($_FILES);
	var_export($_FILES);
	echo '{"success":false,"errors":{"ext-gen524":"File upload error."}}';
} 

// ***** CREATE NEW DIRECTORY ***************************************
elseif ($_POST[cmd] == 'newdir') {
	$dirName = $_POST[dir];
	$newDir = $rootDirectory.$dirName;
	
	@umask(0);
	@mkdir($newDir, 0777);
	if (is_dir($newDir)) {
		echo '{"success":true}';
	} else {
		echo '{"success":false,"error":"Directory was not created: '.$newDir.'"}';
	}
} 

// ***** LOAD TREE **************************************************
elseif ($_POST[cmd] == 'get') {
	$getDir = '../../docs';
	if (!empty($_POST[path])) {
		$getDir .= '/'.$_POST[path];
	}
	echo php_file_tree($getDir, "0");
}	
?>